﻿using ProjScan.RecordManager;
using ProjScan.RecordManager.AssetData;
using ProjScan.ScanRule.Attr;
using UnityEditor;
using UnityEngine;

namespace ProjScan.ScanRule.ProjectAssets.Texture2D
{
    [TextureRuleAttr]
    internal class Texture_TooManyTransparentPixels : RecordRuleImp<TextureAssetData, TextureRecordManager>
    {
        protected override bool IsOK(TextureAssetData assetData)
        {
            return assetData.textureFormat.ToString().Contains("ASTC") || !assetData.isTexture2D || !assetData.hasAlpha || assetData.textureImporterType == TextureImporterType.GUI || assetData.textureImporterType == TextureImporterType.Sprite || assetData.textureImporterType == TextureImporterType.NormalMap || !ProcessAlphaZeros(assetData.textureColorArray, assetData.width, assetData.height);
        }

        private bool ProcessAlphaZeros(Color32[] colors, int width, int height)
        {
            int num = 0;
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int num2 = i * width + j;
                    if (colors[num2].a == 0)
                    {
                        num++;
                    }
                }
            }

            return num * 4 >= width * height * 3;
        }
    }
}